﻿using System;

[assembly: log4net.Config.XmlConfigurator(ConfigFile = @"Log\Log4Net.config", Watch = true)]
namespace CubeStone.Wang.Utilities.Log
{
    /// <summary>
    /// 日志帮助类
    /// </summary>
    public class LogHelper
    {
        #region 各类的Logger
        private static readonly log4net.ILog debugLoger = log4net.LogManager.GetLogger("DebugLogger");
        private static readonly log4net.ILog infoLoger = log4net.LogManager.GetLogger("InfoLogger");
        private static readonly log4net.ILog warnLoger = log4net.LogManager.GetLogger("WarnLogger");
        private static readonly log4net.ILog errorLoger = log4net.LogManager.GetLogger("ErrorLogger");
        private static readonly log4net.ILog fatalLoger = log4net.LogManager.GetLogger("FatalLogger");
        #endregion

        #region Debug级的日志记录

        /// <summary>
        /// Debug级的日志记录
        /// </summary>
        /// <param name="message">记录的信息</param>
        public static void WriteDebugLog(string message)
        {
            if (debugLoger.IsDebugEnabled)
            {
                debugLoger.Debug(message);
            }
        }

        /// <summary>
        /// Debug级的日志记录
        /// </summary>
        /// <param name="ex">异常类</param>
        public static void WriteDebugLog(Exception ex)
        {
            if (debugLoger.IsDebugEnabled)
            {
                debugLoger.Debug("Debug", ex);
            }
        }

        /// <summary>
        /// Debug级的日志记录
        /// </summary>
        /// <param name="message">记录的信息</param>        
        /// <param name="ex">异常类</param>
        public static void WriteDebugLog(string message, Exception ex)
        {
            if (debugLoger.IsDebugEnabled)
            {
                debugLoger.Debug(message, ex);
            }
        }

        #endregion

        #region Info级的日志记录

        /// <summary>
        /// Info级的日志记录
        /// </summary>
        /// <param name="message">记录的信息</param>
        public static void WriteInfoLog(string message)
        {
            if (infoLoger.IsInfoEnabled)
            {
                infoLoger.Info(message);
            }
        }

        /// <summary>
        /// Info级的日志记录
        /// </summary>
        /// <param name="ex">异常类</param>
        public static void WriteInfoLog(Exception ex)
        {
            if (infoLoger.IsInfoEnabled)
            {
                infoLoger.Info("Info", ex);
            }
        }

        /// <summary>
        /// Info级的日志记录
        /// </summary>
        /// <param name="message">记录的信息</param>
        /// <param name="ex">异常类</param>
        public static void WriteInfoLog(string message, Exception ex)
        {
            if (infoLoger.IsInfoEnabled)
            {
                infoLoger.Info(message, ex);
            }
        }
        #endregion

        #region Warn级的日志记录

        /// <summary>
        /// Warn级的日志记录
        /// </summary>
        /// <param name="message">记录的信息</param>
        public static void WriteWarnLog(string message)
        {
            if (warnLoger.IsWarnEnabled)
            {
                warnLoger.Warn(message);
            }
        }

        /// <summary>
        /// Warn级的日志记录
        /// </summary>
        /// <param name="ex">异常类</param>
        public static void WriteWarnLog(Exception ex)
        {
            if (warnLoger.IsWarnEnabled)
            {
                warnLoger.Warn("Warn", ex);
            }
        }

        /// <summary>
        /// Warn级的日志记录
        /// </summary>
        /// <param name="message">记录的信息</param>
        /// <param name="ex">异常类</param>
        public static void WriteWarnLog(string message, Exception ex)
        {
            if (warnLoger.IsWarnEnabled)
            {
                warnLoger.Warn(message, ex);
            }
        }
        #endregion

        #region Error级的日志记录

        /// <summary>
        /// Error级的日志记录
        /// </summary>
        /// <param name="message">记录的信息</param>
        public static void WriteErrorLog(string message)
        {
            if (errorLoger.IsErrorEnabled)
            {
                errorLoger.Error(message);
            }
        }

        /// <summary>
        /// Error级的日志记录
        /// </summary>
        /// <param name="ex">异常类</param>
        public static void WriteErrorLog(Exception ex)
        {
            if (errorLoger.IsErrorEnabled)
            {
                errorLoger.Error("Error", ex);
            }
        }

        /// <summary>
        /// Error级的日志记录
        /// </summary>
        /// <param name="message">记录的信息</param>
        /// <param name="ex">异常类</param>
        public static void WriteErrorLog(string message, Exception ex)
        {
            if (errorLoger.IsErrorEnabled)
            {
                errorLoger.Error(message, ex);
            }
        }
        #endregion

        #region Fatal级的日志记录

        /// <summary>
        /// Fatal级的日志记录
        /// </summary>
        /// <param name="message">记录的信息</param>
        public static void WriteFatalLog(string message)
        {
            if (fatalLoger.IsFatalEnabled)
            {
                fatalLoger.Fatal(message);
            }
        }

        /// <summary>
        /// Fatal级的日志记录
        /// </summary>
        /// <param name="ex">异常类</param>
        public static void WriteFatalLog(Exception ex)
        {
            if (fatalLoger.IsFatalEnabled)
            {
                fatalLoger.Fatal("Fatal", ex);
            }
        }

        /// <summary>
        /// Fatal级的日志记录
        /// </summary>
        /// <param name="message">记录的信息</param>
        /// <param name="ex">异常类</param>
        public static void WriteFatalLog(string message, Exception ex)
        {
            if (fatalLoger.IsFatalEnabled)
            {
                fatalLoger.Fatal(message, ex);
            }
        }
        #endregion
    }
}